package jsu.blogger;

import jsu.blogger.mapper.DraftMapper;
import jsu.blogger.mapper.DraftTagMapper;
import jsu.blogger.pojo.Draft;
import jsu.blogger.service.inter.DraftService;
import org.junit.jupiter.api.Test;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@MapperScan("jsu.blogger.mapper")
public class testDraft {
    @Autowired
    private DraftMapper draftMapper;
    @Test
    void testInsertDraft(){
        Draft draft = new Draft();
        draft.setDraftId("draft1");
        draft.setUserId(1L);
        draft.setPostId(null);
        draft.setTitle("My Draft");
        draft.setContent(null);  // Content为空
        draft.setArticleType("Article");
        draft.setOriginalUrl(null);  // Original URL为空

        draftMapper.insertDraft(draft);

    }
    @Autowired
    private DraftService draftService;
    @Test
    void testFindById(){
        System.out.println(draftService.getDraftById("draft1"));
    }
    @Test
    void testCheckDraftExists(){
        System.out.println(draftService.checkDraftExists("draft1",1L,null));
        System.out.println(draftService.getDraftTitleAndContentById("draft1"));
        System.out.println(draftService.getDraftOtherDetailsById("draft1"));
        System.out.println(draftService.getDraftById("draft1"));
        Draft draft = new Draft();
        draft.setDraftId("draft1");
        draft.setTitle("Updated Title");
        draft.setContent("Updated content");
        draft.setPostId(null);  // postId 为 null
        draft.setArticleType("updated");  // 设置了 articleType
        draft.setOriginalUrl("");  // originalUrl 为空字符串
        draftService.updateDraft(draft);
    }

    @Autowired
    private DraftTagMapper draftTagMapper;
    @Test
    void  teatTags(){
        draftTagMapper.insertDraftTag("draft1",7L);
    }

    @Test
    void testHot(){
        List<Long> longs = Arrays.asList(1L, 2L, 5L, 6L, 7L, 8L, 9L,10L,14L,15L,16L,17L);
        for(long id:longs) {
            draftService.updateHotTopics(id);
        }
    }
}
